home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 293_01 / dep2.c < prev    next >
C/C++ Source or Header  |  1989-08-23  |  3KB  |  93 lines

  1. /*************************  dep2.c  *************************/
  2.  
  3. /*                       Distances.C                        */
  4. /*            distance shading program                      */
  5.  
  6. /*************************************************************
  7.  
  8.       3-D Reconstruction of Medical Images
  9.  
  10.     Three Dimensional Reconstruction Of Medical
  11.     Images from Serial Slices - CT, MRI, Ultrasound
  12.  
  13.  
  14.    These programs process a set of slices images (scans) for one
  15.    patient. It outputs two sets of files containing nine predefined
  16.    views of bony surfaces. One set contains distance values and
  17.    the other gradient values.
  18.  
  19.    The distance values are used as 3-D spatial topographic surface
  20.    coordinate maps for geometrical analysis of the scanned object.
  21.  
  22.    The gradient values are used for rendering the surface maps on
  23.    CRT displays for subjective viewing where perception of small
  24.    surface details is important.
  25.  
  26.     Daniel Geist, B.S.
  27.     Michael W. Vannier, M.D.
  28.  
  29.     Mallinckrodt Institute of Radiology
  30.     Washington University School of Medicine
  31.     510 S. Kingshighway Blvd.
  32.     St. Louis, Mo. 63110
  33.  
  34.     These programs may be copied and used freely for non-commercial
  35.     purposes by developers with inclusion of this notice.
  36.  
  37.  
  38. ********************************************************************/
  39. #include <stdio.h>
  40. #define LINE_SIZE 256
  41. #define HEADER_SIZE 512
  42. #define CTLINE_SIZE 512
  43. int FIRSTSLICE,LASTSLICE,THRESHOLD; /* some global variables */
  44. int  buffer[LINE_SIZE];
  45. char ybuf[LINE_SIZE];
  46. /* input and output files */
  47. char *fnamein="ctbild.000",*fnd="dis.out";
  48.  
  49. /* Set input file name - add number to file extension name*/
  50. setfilename(filenum)
  51. int filenum;
  52. {fnamein[7]=filenum/100+'0';
  53.  fnamein[8]=(filenum%100)/10+'0';
  54.  fnamein[9]='0'+filenum%10;
  55. }
  56. create_distance_shades()
  57. {int z,x,y;
  58.  FILE *fd,*fn;
  59.   fd=fopen(fnd,"wb");                  /*open output file */
  60.   for(z=0;z<(LASTSLICE-FIRSTSLICE+1);z++){  /* for each slice*/
  61.       setfilename(FIRSTSLICE+z);       /*open slice file */
  62.       fn=fopen(fnamein,"rb");
  63.       fseek(fn,(long)HEADER_SIZE,SEEK_SET);    /* read header    */
  64.       for(y=0;y<LINE_SIZE;y++){           /*for each line */
  65.           fread(buffer,1,CTLINE_SIZE,fn);   /*read line */
  66.           /* find Threshold transition */
  67.           for(x=1;(x<LINE_SIZE) && (buffer[x]<THRESHOLD);x++);
  68.           if(x<LINE_SIZE) ybuf[y]=LINE_SIZE-x;  /* if transition then distance shade */
  69.           else ybuf[y]=0;           /*else empty */
  70.       }
  71.       fclose(fn);              /*close scan file */
  72.       fwrite(ybuf,1,LINE_SIZE,fd);
  73.       printf("did %d \n",z);
  74.   }
  75.   fclose(fd);                /* close output file */
  76. }
  77. /**********************************************************/
  78. /**** MAIN ***** MAIN ***** MAIN ***** MAIN ***** MAIN ****/
  79. /**********************************************************/
  80. main()
  81. {
  82.  /* first get some parameters from user */
  83.  printf("Enter Starting scan number: ");
  84.  scanf("%d",&FIRSTSLICE);
  85.  printf("Enter ending scan number: ");
  86.  scanf("%d",&LASTSLICE);
  87.  printf("Enter threshold number: ");
  88.  scanf("%d",&THRESHOLD);
  89.  THRESHOLD+=1024;
  90.  
  91.  create_distance_shades();
  92. }
  93.